﻿@using XRM.Security.DataAccess.Enums
@using XRM.Security.WebUI.Enums
@using XRM.Security.WebUI.Security
@functions {

    readonly string[] userRoles = UserPrincipal.Current.Roles;
    private bool IsUserInRole(IEnumerable<string> roles)
    {
        return roles.Intersect(userRoles).Any();
    }
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>АИС «СКАЗИ» - @ViewBag.Title</title>
    <link href="@Url.Content("~/Content/css/bootstrap.css")" rel="stylesheet" />
    <link href="@Url.Content("~/Content/css/metisMenu.css")" rel="stylesheet" />
    <link href="@Url.Content("~/Content/css/dataTables.bootstrap.css")" rel="stylesheet" />
    <link href="@Url.Content("~/Content/css/sb-admin-2.css")" rel="stylesheet" />
    <link href="@Url.Content("~/Content/css/custom.css")" rel="stylesheet" />
    <link href="@Url.Content("~/Content/fonts/font-awesome-4.1.0/css/font-awesome.min.css")" rel="stylesheet" />
    
    @Styles.Render("~/bundles/jquery-css")

    @RenderSection("styles", false)
    
    @Scripts.Render("~/bundles/common")
    @Scripts.Render("~/bundles/jqueryval")
</head>
<body>
    @{
        string cName = ViewContext.RouteData.Values["controller"].ToString();
    }
    @Html.Hidden("hdRootUrl", Url.Content("~"))

    <div id="wrapper">
        <nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="@Url.Action("Index", "Home")">АИС «СКАЗИ»</a>
            </div>
            <ul class="nav navbar-top-links navbar-right">
                <li class="dropdown">
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                        <i class="fa fa-user fa-fw"></i> @UserPrincipal.Current.DisplayName <i class="fa fa-caret-down"></i>
                    </a>
                    <ul class="dropdown-menu dropdown-user">
                        @*<li>
                                <a href="#"><i class="fa fa-user fa-fw"></i> Информация о пользователе</a>
                            </li>
                            <li class="divider"></li>*@
        <li>
                            <a href="@Url.Action("LogOff", "Account")"><i class="fa fa-sign-out fa-fw"></i> Выход</a>
                        </li>
                    </ul>
                </li>
            </ul>
        </nav>
                <div class="subnavbar">
                    <div class="subnavbar-inner">
                        <div class="container">
                            <ul class="mainnav">
                                <li class="@(cName.Equals("Home")?"active":"")">
                                    <a href="@Url.Action("Index", "Home")">
                                        <i class="fa fa-home"></i>
                                        <span>Главная</span>
                                    </a>
                                </li>
                                @if (IsUserInRole(new[] { UserRoles.Administrator.ToString(), UserRoles.UsersReestrSertificateEditor.ToString(),
                                    UserRoles.UsersReestrSkziEditor.ToString(), UserRoles.UsersReestrSoftwareEditor.ToString() }))
                                {
                                    <li class="@(cName.Equals("Request")?"active":"")">
                                        <a href="@Url.Action("Index", "Request")">
                                            <i class="fa fa-list-alt"></i>
                                            <span>Заявки</span>
                                        </a>
                                    </li>
                                }
                                
                                @if ( IsUserInRole( new[] { UserRoles.Administrator.ToString(), UserRoles.UsersReestrSertificateEditor.ToString(),
                                    UserRoles.UsersReestrSkziEditor.ToString(), UserRoles.UsersReestrSoftwareEditor.ToString() } ) )
                                {
                                    <li class="@(cName.Equals("UserRegister")?"active":"")">
                                        <a href="@Url.Action("Index", "UserRegister")" >
                                            <i class="fa fa-users"></i>
                                            <span>Пользователи</span>
                                        </a>
                                    </li>
                                }

                                @if (IsUserInRole(new[] { UserRoles.Administrator.ToString(), UserRoles.UsersReestrSertificateEditor.ToString() }))
                                {
                                    <li class="@(cName.Equals("CertRegister")?"active":"")">
                                        <a href="@Url.Action("Index", "CertRegister")">
                                            <i class="fa fa-file-text-o"></i>
                                            <span>Сертификаты</span>
                                        </a>
                                    </li>
                                }

                                @if (IsUserInRole(new[] { UserRoles.Administrator.ToString(), UserRoles.UsersReestrSkziEditor.ToString() }))
                                {
                                    <li class="@(cName.Equals("UserSkzi")?"active":"")">
                                        <a href="@Url.Action("Index", "UserSkzi")">
                                            <i class="fa fa-database"></i>
                                            <span>СКЗИ</span>
                                        </a>
                                    </li>
                                }


                                @if (IsUserInRole(new[] { UserRoles.Administrator.ToString(), UserRoles.ReportEditor.ToString() }))
                                {
                                    <li class="@(cName.Equals("Report")?"active":"")">
                                        <a href="@Url.Action("Index", "Report")">
                                            <i class="fa fa-bar-chart-o"></i>
                                            <span>Отчеты</span>
                                        </a>
                                    </li>
                                }
                                @if (IsUserInRole(new[] { UserRoles.Administrator.ToString(),
                                    UserRoles.InfoSystemViewer.ToString(), UserRoles.InfoSystemEditor.ToString(),
                                    UserRoles.IdentityCenterViewer.ToString(), UserRoles.IdentityCenterEditor.ToString(),
                                    UserRoles.SkziKindViewer.ToString(), UserRoles.SkziKindEditor.ToString(),
                                    UserRoles.WorkKindViewer.ToString(), UserRoles.WorkKindEditor.ToString(),
                                    UserRoles.StructDepartmentViewer.ToString(), UserRoles.StructDepartmentEditor.ToString()
                                }))
                                {
                                    var active = cName.Equals( "SkziKind" ) || cName.Equals( "InfoSystem" ) || cName.Equals( "IdentityCenter" ) ||
                                        cName.Equals( "WorkKind" ) || cName.Equals( "Department" );
                                    
                                    <li class="dropdown @(active?"active":"")">
                                        <a href="javascript:" class="dropdown-toggle" data-toggle="dropdown">
							                <i class="fa fa-book"></i>
                                            <span>Справочники</span>
                                            <b class="caret"></b>
                                        </a>
                                        <ul class="dropdown-menu">
                                            @if (IsUserInRole(new[] { UserRoles.Administrator.ToString(),
                                                    UserRoles.SkziKindViewer.ToString(), UserRoles.SkziKindEditor.ToString()
                                                }))
                                            {
                                                <li>
                                                    <a href="@Url.Action("Index", "SkziKind")">СКЗИ</a>
                                                </li>
                                            }

                                            @if (IsUserInRole(new[] { UserRoles.Administrator.ToString(),
                                                    UserRoles.InfoSystemViewer.ToString(), UserRoles.InfoSystemEditor.ToString()
                                                }))
                                            {
                                                <li>
                                                    <a href="@Url.Action("Index", "InfoSystem")">Информационные системы</a>
                                                </li>
                                            }

                                            @if (IsUserInRole(new[] { UserRoles.Administrator.ToString(),
                                                    UserRoles.IdentityCenterViewer.ToString(), UserRoles.IdentityCenterEditor.ToString(),
                                                }))
                                            {
                                                <li>
                                                    <a href="@Url.Action("Index", "IdentityCenter")">Удостоверяющие центры</a>
                                                </li>
                                            }

                                            @if (IsUserInRole(new[] { UserRoles.Administrator.ToString(),
                                                    UserRoles.WorkKindViewer.ToString(), UserRoles.WorkKindEditor.ToString()
                                                }))
                                            {
                                                <li>
                                                    <a href="@Url.Action("Index", "WorkKind")">Виды работ</a>
                                                </li>
                                            }

                                            @if (IsUserInRole(new[] { UserRoles.Administrator.ToString(),
                                                    UserRoles.StructDepartmentViewer.ToString(), UserRoles.StructDepartmentEditor.ToString()
                                                }))
                                            {
                                                <li>
                                                    <a href="@Url.Action("Index", "Department")">Структурные подразделения</a>
                                                </li>
                                            }

                                        </ul>
                                    </li>
                                }

                                @if (IsUserInRole(new[] { UserRoles.Administrator.ToString(), UserRoles.SystemUserEditor.ToString() }))
                                {
                                    <li class="@(cName.Equals("SystemUser")?"active":"")">
                                        <a href="@Url.Action("Index", "SystemUser")">
                                            <i class="fa fa-user"></i>
                                            <span>Сотрудники</span>
                                        </a>
                                    </li>
                                }
                            </ul>
                        </div>
                    </div>
                </div>
        <!-- Page Content -->
        <div id="page-wrapper">
            @if ( ViewBag.HideHeader != true )
            {
                <div class="row">
                    <div class="col-lg-12">
                        <h1 class="page-header">@ViewBag.Title</h1>
                    </div>
                </div>
            }
            <div class="row">
                <div class="col-lg-9">
                    @{
                        var alertMessage = (string) TempData["AlertMessage"];
                        if (alertMessage != null)
                        {
                            var alertType = TempData["AlertType"] != null ? (AlertType)TempData["AlertType"] : AlertType.Empty;

                            var alertClass = String.Empty;

                            switch (alertType)
                            {
                                case AlertType.Error: alertClass = "alert alert-danger alert-dismissable"; break;

                                case AlertType.Warning: alertClass = "alert alert-info alert-dismissable"; break;

                                case AlertType.Success: alertClass = "alert alert-success alert-dismissable"; break;
                            }
                            <div class="@alertClass" id="alert-message">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>    
                                @Html.Raw(alertMessage)
                            </div>
                        }
                    }

                    @RenderBody()

                </div>
                <div class="col-lg-3">
                    @RenderSection("History", false)
                </div>
            </div>
        </div>
    </div>

    @RenderSection("scripts", false)
</body>
</html>
